

using System;

namespace ABA
{
    public class Loader : UnitySingleton<Loader>
    {
        Action loadCompleteCB;
        Action<Action>[] actions;

        int cur = 0;
        bool isCurExe = false;
        private void UpdateProgress()
        {
            cur++;
            isCurExe = false;
            Event.inst.Send<double, string>(CommData.EVENT_LOADING_BAR_UPDATE, cur, "");
        }

        private void Update()
        {
            if (actions == null || actions.Length == 0) return;

            if (isCurExe == false)
            {
                isCurExe = true;
                actions[cur](UpdateProgress);
            }
        }

        ///////////////////////////////////////////login game  资源加载///////////////////////////////////////////////////////////////////
        public void LoginGame(Action cb)
        {
            loadCompleteCB = () =>
            {
                //Event.inst.RemoveListener<int>((int)GameEvent.RECONNECT_OK, "Loader");
                cb();
            };

            // 重要：加载开始一定要注册这个消息，加载结束一定要去掉这个注册
            //Event.inst.AddListener<int>((int)GameEvent.RECONNECT_OK, "Loader", _LoginGame);
            _LoginGame(1);
        }

        private void _LoginGame(int v)
        {
            //ui


            //config


            //
        }
    }

}